package joodle.domain;

/**
 * A point representing a location in (x,y) coordinate space, specified in integer 
 * precision.
 */

public class Point {
	private float x;
	private float y;
	
	/**
	 * Constructs and initializes a point at the specified (x,y) location in the 
	 * coordinate space.
	 * @param x the X coordinate of the newly constructed Point
	 * @param y the Y coordinate of the newly constructed Point
	 */
	public Point(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	/**
	 * Constructs and initializes a point at the origin (0, 0) of the coordinate space.
	 */
	public Point() {
		this(0, 0);
	}
	
	/**
	 * Returns the X coordinate of this Point2D in float precision. 
	 * @return the X coordinate of this Point2D.
	 */
	public float getX() {
		return x;
	}
	
	/**
	 * Returns the Y coordinate of this Point2D in float precision. 
	 * @return the Y coordinate of this Point2D.
	 */
	public float getY() {
		return y;
	}
	/**
	 * Constructs and initializes a Point2D with the specified coordinates.
	 * @return a Point2D object with the specified coordinates.
	 */
	public java.awt.geom.Point2D awtPoint() {
		return new java.awt.geom.Point2D.Float(x, y);
	}
	
	/**
	 * Determines whether or not two points are equal. Two instances of Point2D are equal 
	 * if the values of their x and y member fields, representing their position in the 
	 * coordinate space, are the same.
	 * @param o an object to be compared with this Point2D 
	 * @return true if the object to be compared is an instance of Point2D and has the 
	 * same values; false otherwise. 
	 */
	@Override
	public boolean equals(Object o) {
		if(o instanceof Point) {
			Point p = (Point) o;
			return x == p.x && y == p.y;
		}
		return false;
	}
	
	/**
	 * Returns a string representation of this point and its location in the (x,y) 
	 * coordinate space.
	 * @return a string representation of this point
	 */
	@Override
	public String toString() {
		return "[x=" + x + ", y=" + y + "]";
	}
	/**
	 * Returns the smaller one of the two parameter points
	 * @param p1 the point to be checked
	 * @param p2 the point to be checked
	 * @return the minimum of the two
	 */
	public static Point minPoint(Point p1, Point p2) {
		float x = Math.min(p1.getX(), p2.getX());
		float y = Math.min(p1.getY(), p2.getY());
		
		return new Point(x, y);
	}
	/**
	 * Returns the bigger one of the two parameter points
	 * @param p1 the point to be checked
	 * @param p2 the point to be checked
	 * @return the maximum of the two
	 */
	public static Point maxPoint(Point p1, Point p2) {
		float x = Math.max(p1.getX(), p2.getX());
		float y = Math.max(p1.getY(), p2.getY());
		
		return new Point(x, y);
	}
}
